package com.orhon.smartcampus.modules.systemctl.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.*;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
//@EqualsAndHashCode
@Entity
@Table(name = "systemctl_menus", schema = "smartcloud", catalog = "")
public class Menus {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Long id;
    @Column(name = "title", nullable = true)
    private String title;
    @Column(name = "name", nullable = true, length = 255)
    private String name;
    @Column(name = "path", nullable = true, length = 255)
    private String path;
    @Column(name = "component", nullable = true, length = 255)
    private String component;
    @Column(name = "category", nullable = true, length = 255)
    private String category;
    @Column(name = "type", nullable = true, length = 255)
    private String type;
    @Column(name = "level", nullable = true)
    private Integer level;
    @Column(name = "meta", nullable = true)
    private String meta;
    @Column(name = "clients", nullable = true)
    private String clients;
    @Column(name = "icon", nullable = true, length = 255)
    private String icon;
    @Column(name = "ordered", nullable = true)
    private Integer ordered;

    @Transient
    @Column(name = "parent_id", nullable = true)
    private Integer parent_id;

    @Transient
    @Column(name = "module_id", nullable = true)
    private Integer module_id;


    @Column(name = "status", nullable = false)
    private Integer status;
    @Column(name = "created_at", nullable = false)
    private Date createdAt;
    @Column(name = "updated_at", nullable = true)
    private Date updatedAt;
    @Column(name = "deleted_at", nullable = true)
    private Date deletedAt;


    @ManyToOne(fetch = FetchType.LAZY)
    @Where(clause = "ISNULL(deleted_at)")
    @JoinColumn(name = "module_id", referencedColumnName = "id")
    @NotFound(action=NotFoundAction.IGNORE)
    private Modules modules;


    @ManyToOne(fetch = FetchType.LAZY)
    @Where(clause = "ISNULL(deleted_at)")
    @JoinColumn(name = "parent_id", referencedColumnName = "id")
    @NotFound(action=NotFoundAction.IGNORE)
    private Menus menus;
    
    @OneToMany(fetch = FetchType.LAZY)
    @Where(clause = "ISNULL(deleted_at)")
    @JoinColumn(name = "parent_id", referencedColumnName = "id")
    @NotFound(action=NotFoundAction.IGNORE)
    private List<Menus> childreen;

    @OneToMany(fetch = FetchType.LAZY)
    @Where(clause = "ISNULL(deleted_at)")
    @JoinColumn(name = "menu_id", referencedColumnName = "id")
    @NotFound(action=NotFoundAction.IGNORE)
    private List<Widgets> widgets;

    @ManyToMany( cascade = CascadeType.ALL , fetch = FetchType.LAZY)
    @Where(clause = "ISNULL(deleted_at)")
    @JoinTable(name = "systemctl_api_page_relation",
            joinColumns = { @JoinColumn(name = "menu_id")},
            inverseJoinColumns = { @JoinColumn(name = "api_id")})
    List<Apis> apis;

	@Override
	public String toString() {
		return "Menus [id=" + id + "]";
	}
    
    
    
}
